﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq.Dynamic;
using System.Web.Mvc;
using ChoViet.CMS.ViewModels;
using ChoViet.Lib.Common;
using ChoViet.Lib.Helpers;
using ChoViet.Lib.Paging;
using ChoViet.Model;
using MVCMessage;
using ChoViet.Lib.Mail;
using System.Configuration;
using System.IO;

namespace ChoViet.CMS.Controllers
{
    public class HappyBirdthDayController : BaseController
    {
        /// <summary>
        /// Created by: VietLv
        /// Created date: 29/06/2012
        /// Description: Manage tags
        /// </summary>

        ChoVietDataContext eDataContext = new ChoVietDataContext();

        #region GET/Index
        public ActionResult Index(int id)
        {
            try
            {
                var model = new HappyBirdthDayViewModel();
                model.User = eDataContext.Users.FirstOrDefault(e => e.ID == id);
                return View(model);
            }
            catch (Exception ex)
            {
                ViewData["MessageInfo"] = ex.Message;
                return View();
            }
        }
        #endregion
        #region 
        [HttpPost]
        public ActionResult Index()
        {
            try
            {
                // Gửi mail kích hoạt
                string subject = "Chợ102.vn - Chúc mừng sinh nhật bạn Nông Khánh";
                string fromMail = ConfigurationManager.AppSettings["DefaultFromMail"];

                try
                {
                    StreamReader Srd = new StreamReader(@"D:\Project\Example_Asp.net_MVC\Choviet.zoo.vn\SourceCode\ChoViet\ChoViet.CMS\EmailTemplates\HappyBirdthDay.txt");
                    var c = "";
                    string content = "";
                    while ((c= Srd.ReadLine())!= null)
                    {
                        content += c;
                    }
                    Srd.Dispose();
                    Srd.Close();
                    var body = "chưa có  nội dung";
                    body = content;
                    SmtpMailer.sendMail("lehoangviet.hp@gmail.com", fromMail, subject, body);
                }
                catch (Exception)
                {
                    throw new IndexOutOfRangeException();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return View();
        }
        #endregion

    }
}
